package com.javaProject.controller;


import com.javaProject.dto.R;
import com.javaProject.entity.Student;
import com.javaProject.service.StudentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.InvalidKeySpecException;
import java.util.List;
@CrossOrigin
@Tag(name = "学生接口",description = "这个接口用户增删改查等功能")
@RestController
public class studentController {

    @Autowired
    private StudentService studentService;

    @Operation(summary = "学生登陆",description = "两个字段，账号和密码")
    @Parameters({
            @Parameter(name = "username",description = "账号",deprecated = true),
            @Parameter(name = "password",description = "密码",deprecated = true)
    })
    @GetMapping("/student")
    public R login(String username,String password) throws NoSuchAlgorithmException, InvalidKeySpecException {
        Student student = new Student();
        student.setUsername(username);
        student.setPassword(password);
        return studentService.login(student);
    }



    @Operation(summary = "学生新增",description = "需要学生的所有字段,至少要给用户名和密码")
    @PostMapping("/student")
    public R add(@RequestBody Student student) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException {
        System.out.println(student);
        return studentService.add(student);
    }


    @Operation(summary = "学生删除",description = "需要学生id")
    @Parameter(name = "username",description = "学生用户名",deprecated = true)
    @PutMapping("/student")
    public R Delect(@RequestBody Student student){
        return studentService.Delect(student);
    }


    @Operation(summary = "学生数据更新",description = "需要学生所有信息，不给的值默认为空")
    @PutMapping("/student/upData")
    public R upData(@RequestBody Student student) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException {
        return studentService.upData(student);
    }


    @Operation(summary = "查询所有信息",description = "无需数据，返还整个学生表")
    @PostMapping("/student/getAllStudent")
    public List<Student> getAllStudent() throws NoSuchAlgorithmException, InvalidKeySpecException {
        return studentService.getAllTeacher();
    }


}
